package com.lipy.customizeconfigserver.refresh.scope;

import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @description: 自定义scope
 * @author: lipy
 * @create: 2020-07-05 10:17
 **/

public class MyRefreshScope implements Scope {
    private ConcurrentHashMap<String,Object> map = new ConcurrentHashMap<>();

    @Override
    public Object get(String name, ObjectFactory<?> objectFactory) {
        if(map.containsKey(name)){
            return map.get(name);
        }
        Object object = objectFactory.getObject();
        map.put(name, object);
        return object;
    }

    @Override
    public Object remove(String name) {
        return map.remove(name);
    }

    @Override
    public void registerDestructionCallback(String s, Runnable runnable) {

    }

    @Override
    public Object resolveContextualObject(String s) {
        return null;
    }

    @Override
    public String getConversationId() {
        return null;
    }
}
